﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Common.Log
{
    // 
    public static class PlatformDetector
    {
        // 
        public static RuntimeOs CurrentOS
        {
            get
            {
                return PlatformDetector.currentOS;
            }
        }

        // 
        public static bool IsDesktopWin32
        {
            get
            {
                return PlatformDetector.currentOS == RuntimeOs.Windows || PlatformDetector.currentOS == RuntimeOs.WindowsNT;
            }
        }

        // 
        public static bool IsWin32
        {
            get
            {
                return PlatformDetector.currentOS == RuntimeOs.Windows || PlatformDetector.currentOS == RuntimeOs.WindowsNT || PlatformDetector.currentOS == RuntimeOs.WindowsCE;
            }
        }

        // 
        public static bool IsUnix
        {
            get
            {
                return PlatformDetector.currentOS == RuntimeOs.Unix;
            }
        }

        // 
        private static RuntimeOs GetCurrentRuntimeOS()
        {
            PlatformID platform = Environment.OSVersion.Platform;
            if (platform == PlatformID.Unix || platform == (PlatformID)128)
            {
                return RuntimeOs.Unix;
            }
            if (platform == PlatformID.WinCE)
            {
                return RuntimeOs.WindowsCE;
            }
            if (platform == PlatformID.Win32Windows)
            {
                return RuntimeOs.Windows;
            }
            if (platform == PlatformID.Win32NT)
            {
                return RuntimeOs.WindowsNT;
            }
            return RuntimeOs.Unknown;
        }

        // 
        private static RuntimeOs currentOS = PlatformDetector.GetCurrentRuntimeOS();
    }
}
